#include"LPC11XX.H"

void Delay()
{
	uint16_t i,j;
	
	 for(i=0;i<5000;i++)
	   for(j=0;j<200;j++);
}
void LedInit(void)
{
	LPC_SYSCON->SYSAHBCLKCTRL|=(1<<16);
	LPC_IOCON->PIO2_0&=~0x07;
	LPC_IOCON->PIO2_0|=0x00;
	
	
	
	LPC_IOCON->PIO2_1&=~0x07;
	LPC_IOCON->PIO2_1|=0x00;
	
	
	
	LPC_IOCON->PIO2_2&=~0x07;
	LPC_IOCON->PIO2_2|=0x00;
	
	
	
  LPC_IOCON->PIO2_3&=~0x07;
	LPC_IOCON->PIO2_3|=0x00;
	
	 
	 
	LPC_IOCON->PIO2_4&=~0x07;
	LPC_IOCON->PIO2_4|=0x00;
	
	
	
	LPC_IOCON->PIO2_5&=~0x07;
	LPC_IOCON->PIO2_5|=0x00;
	
	
	
	LPC_IOCON->PIO2_6&=~0x07;
	LPC_IOCON->PIO2_6|=0x00;
	
	
	
	LPC_IOCON->PIO2_7&=~0x07;
	LPC_IOCON->PIO2_7|=0x00;
	
	LPC_SYSCON->SYSAHBCLKCTRL&=~(1<<16);
	LPC_SYSCON->SYSAHBCLKCTRL|=(1<<6);
	
  LPC_GPIO2->DIR|=0xff;
	LPC_GPIO2->DATA|=0xff;
}

int main()
{
	
	int i;
	LedInit();
		
		while(1)
		{
		for(i=0;i<8;i++)
		{
			
			Delay();
			LPC_GPIO2->DATA&=~(1<<i);
      Delay(); 
			LPC_GPIO2->DATA|=(1<<i);
		}
		
		for(i=6;i>=0;i--)
		{
			
			Delay();
			LPC_GPIO2->DATA&=~(1<<i);
      Delay(); 
			LPC_GPIO2->DATA|=(1<<i);
		}
	}
		
	}